package com.tduck.cloud.dashboard.service.impl;


import cn.hutool.core.util.StrUtil;
import com.tduck.cloud.dashboard.constant.DashboardConstants;
import com.tduck.cloud.dashboard.request.ChartDataRequest;
import com.tduck.cloud.dashboard.service.charts.BaseDashboardChartDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 获取图表数据
 *
 * @author tduck
 */
@Service
public class DashboardChartDataService {

    @Autowired
    private Map<String, BaseDashboardChartDataService> chartDataServiceMap;

    /**
     * 获取图表数据
     *
     * @param request 请求
     * @return
     */
    public Map<String, Object> getChartData(ChartDataRequest request) {
        // 首字母小写
        String chartType = request.getChartType();
        BaseDashboardChartDataService baseChartDataService = chartDataServiceMap.get(DashboardConstants.DASHBOARD_CHART_PREFIX + chartType + "ChartDataService");
        if (null != baseChartDataService) {
            return baseChartDataService.getChartData(request);
        } else {
            return chartDataServiceMap.get(DashboardConstants.DASHBOARD_CHART_PREFIX + "DefaultChartDataService").getChartData(request);
        }
    }
}
